package com.java.collectionSort;

import java.util.*;
import java.util.function.Predicate;

public class SortDemo {
    public static void main(String[] args) {

        /*List<String> list = new ArrayList<>();
        list.add("hello");
        list.add("world");
        list.add("java");
        list.add("Python");
        list.add("C");
        list.add("C++");
        list.add("C#");
        list.add("JavaScript");
        list.add("PHP");
        list.add("Go");
        Collections.sort(list);
        //输出
        for (String str : list){
            System.out.println(str);
        }*/
        Scanner scanner = new Scanner(System.in);
        List<Person> persons = new ArrayList<>();
        persons.add(new Person(7, 20, "吴九", "男"));
        persons.add(new Person(8, 32, "郑十", "男"));
        persons.add(new Person(1, 20, "张三", "男"));
        persons.add(new Person(4, 23, "赵六", "男"));
        persons.add(new Person(5, 19, "孙七", "男"));
        persons.add(new Person(6, 34, "周八", "男"));
        persons.add(new Person(2, 21, "李四", "男"));
        persons.add(new Person(3, 48, "王五", "男"));
        persons.add(new Person(9, 28, "王十", "男"));

        //获得Stream流
        persons.stream()
                .filter((p) -> p.getGender().equals("男"))
                .filter((p) -> p.getAge() > 25)
                .map((p) -> {p.setAge(p.getAge() + 2); return p;})
                .forEach((p) -> System.out.println(p));
        /*//排序
        Collections.sort(persons);
        //输出
        for (Person p : persons){
            System.out.println(p.getId()+" "+p.getName()+" "+p.getAge()+" "+p.getGender());

            //调用重写的方法
            //System.out.println(p);
        }

        System.out.println("------------------");
        System.out.println("请选择排序方式：1、按照编号 2、按照年龄 3按照姓名");
        System.out.println("-----------");
        int op = scanner.nextInt();
        switch (op){
            case 1:
                //第一种方式，使用外部类
                //Collections.sort(persons, new IdComparator());

                //第二种方式, 匿名内部类
                *//*Collections.sort(persons, new Comparator<Person>() {
                    @Override
                    public int compare(Person o1, Person o2) {
                        return 0;
                    }
                });*//*
                //第三种方式，lambda表达式
                Collections.sort(persons,(p1,p2) -> p1.getId()-p2.getId());
                break;
            case 2:
                Collections.sort(persons, new AgeComparator());
                break;
            case 3:
                Collections.sort(persons, new NameComparator());
                break;
            default:
                System.out.println("输入有误");
        }*/
        //输出
        /*for (Person p : persons){
            System.out.println(p.getId()+" "+p.getName()+" "+p.getAge()+" "+p.getGender());
        }*/
        //Lambda表达式实现
        persons.forEach(p -> System.out.println(p));
    }
}
